#!/bin/bash

# Every X minutes (determines by crontab) check toner levels and append to a file. This file will contain date, time and toner stats

# Create the array for printer names

printer_names=( baskerville cleveland lib_iif lib_1st_flr lib_2nd_flr norris2 read2 \
		scilab scilib jrc_email younker2 helpdesk2 duerer gencomp2 inslab2 rose ccl3_bw )

for ((i=0; i < ${#printer_names[@]}; i++))
do

# First, write the date to the file -- note that this may not be the best date format

echo `date '+%c'` >> $HOME/printers/toner_level/toner_stats/"${printer_names[$i]}"_toner_stats

# Now, append the toner level to the file
# Should have a backup if the toner level file is empty

printf "%d\n" `cat $HOME/printers/toner_level/"${printer_names[$i]}"_level` >> $HOME/printers/toner_level/toner_stats/"${printer_names[$i]}"_toner_stats
done

# Escher is the exception, since it's a color printer...

echo `date '+%c'` >> $HOME/printers/toner_level/toner_stats/escher_black_toner_stats
echo `date '+%c'` >> $HOME/printers/toner_level/toner_stats/escher_cyan_toner_stats
echo `date '+%c'` >> $HOME/printers/toner_level/toner_stats/escher_magenta_toner_stats
echo `date '+%c'` >> $HOME/printers/toner_level/toner_stats/escher_yellow_toner_stats

printf "%d\n" `cat $HOME/printers/toner_level/escher_black_level` >> $HOME/printers/toner_level/toner_stats/escher_black_toner_stats
printf "%d\n" `cat $HOME/printers/toner_level/escher_cyan_level` >> $HOME/printers/toner_level/toner_stats/escher_cyan_toner_stats
printf "%d\n" `cat $HOME/printers/toner_level/escher_magenta_level` >> $HOME/printers/toner_level/toner_stats/escher_magenta_toner_stats
printf "%d\n" `cat $HOME/printers/toner_level/escher_yellow_level` >> $HOME/printers/toner_level/toner_stats/escher_yellow_toner_stats

exit 0
